package com.usoft2;

import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.Props;
import akka.actor.UntypedActor;

/**
 * Created by liyanxin on 2015/1/12.
 */
public class HelloWorld {


    public static class StartActor extends UntypedActor {

        @Override
        public void preStart() throws Exception {
            /**
             * Props.create 方法，第一个参数是MyActor class，后边的参数是参数化列表，
             * 表示传入其构造器的参数
             */
            final ActorRef child =
                    getContext().actorOf(Props.create(MyActor.class, 4, 5), "myChild");
            child.tell("good morning", this.getSelf());
        }

        @Override
        public void onReceive(Object message) throws Exception {
            System.out.println("result=" + message);
            this.getContext().stop(this.getSelf());
        }
    }

    public static void main(String args[]) {
        ActorSystem system = ActorSystem.create("myActorSystem");
        system.actorOf(Props.create(StartActor.class), "helloWorld");
    }
}
